package logic

import (
	"context"
	"fmt"
	"srv/model/redis"

	"srv/cart"
	"srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CountCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCountCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CountCartLogic {
	return &CountCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CountCartLogic) CountCart(in *cart.CountCartRequest) (*cart.CountCartResponse, error) {
	// todo: add your logic here and delete this line
	countCart, err := redis.CountCart(in.UserId)
	if err != nil {
		logx.Error("总数获取失败")
		return nil, fmt.Errorf("总数获取失败")
	}
	return &cart.CountCartResponse{Count: countCart}, nil
}
